package com.example.coursehub.coursemanagement.repository;

import com.example.coursehub.coursemanagement.entity.Course;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 课程数据访问接口
 */
@Repository
public interface CourseRepository extends JpaRepository<Course, Long> {
    
    /**
     * 根据教师ID查找课程
     */
    List<Course> findByTeacherId(Long teacherId);
    
    /**
     * 根据课程名称模糊查询
     */
    @Query("SELECT c FROM Course c WHERE c.name LIKE %:name%")
    List<Course> findByNameContaining(@Param("name") String name);
    
    /**
     * 统计教师的课程数量
     */
    long countByTeacherId(Long teacherId);
}